package com.shaozi.nc.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shaozi.lib.logger.DBLogger;
import com.shaozi.utils.common.DebugConfigHelper;

@Component
@Aspect
public class MQBusAop {

	private Logger log = Logger.getLogger(MQBusAop.class);
	@Autowired
	private DBLogger dbLogger;
	@Autowired
	private DebugConfigHelper debugHelper;

	public MQBusAop() {

	}

	@Pointcut(value = "execution(public void com.shaozi.data.mq.business.MqBusImpl.decomposeData(..))")
	public void cutExecute() {
		// logger.debug("point cut");
	}

	@Before("cutExecute()")
	public void beforeExecute(JoinPoint jp) {
		if (!debugHelper.isWarnEnable())
			return;
		String logType = jp.getTarget().getClass().getSimpleName();
		if (jp.getArgs().length == 0)
			return;
		String workJson = (String) jp.getArgs()[0];
		String destName = (String) jp.getArgs()[1];
		String uuid = (String) jp.getArgs()[3];
		dbLogger.save("", "nc_" + logType, workJson, destName, 4, uuid);
	}

}
